update Stock_Item set Original_Purchase_Date = (select created from Buyshop_Transaction where Buyshop_Transaction_ID = (select Buyshop_Transaction_id from Buyshop_Trans_Line btl where btl.Buyshop_Trans_Line_ID = stock_item.Buyshop_Trans_Line_ID) ) where stock_item_id in ( select Stock_Item_ID from stock_item where item_stock_type_id in (1,2,3) and Stock_Item_ID in ( select stock_item_id from Stock_Item_Count where Stock_Holding_Group_ID in (1) and Stock_Count > 0)); Go update stock_item set Target_Release_Date = (select maturityDate from ssb where SSB_ID = (select ssb_id from ssb_item si where si.Stock_Item_ID = Stock_Item.Stock_Item_ID) ) where Stock_Item_ID in (select Stock_Item_ID from stock_item where item_stock_type_id in (3) and Stock_Item_ID in ( select stock_item_id from Stock_Item_Count where Stock_Holding_Group_ID in (1) and Stock_Count > 0)); Go update ssb set Repayment_Amount = (case when InitiationFeePaid = 1 then Secured_Amount else Secured_Amount + InitiationFee end) where Repayment_Amount is null; GO update ssb set IsExtended = 1 where ssb_id in (select ssbid from SingleExtensionLog where ssbid in ( (select ssb_id from ssb where ssb_id in (select ssb_id from ssb_item where stock_item_id in (select Stock_Item_ID from stock_item where Item_Stock_Type_ID = 3 and stock_item_id in (select stock_item_id from Stock_Item_Count where Stock_Holding_Group_ID in (1) and Stock_Count > 0)))))); Go update ssb set ExtendedOn = (select top 1 created from SingleExtensionLog where SSBID = ssb.SSB_ID order by Created desc) where SSB_ID in (select ssb_id from ssb where ssb_id in (select ssb_id from ssb_item where stock_item_id in (select Stock_Item_ID from stock_item where Item_Stock_Type_ID = 3 and stock_item_id in (select stock_item_id from Stock_Item_Count where Stock_Holding_Group_ID in (1) and Stock_Count > 0)))); GO update ssb set AdminFeePaidToDate = DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, ExtendedOn) + 1, 0)) where ExtendedOn is not null and ssb_id in (select ssb_id from ssb_item where stock_item_id in (select Stock_Item_ID from stock_item where Item_Stock_Type_ID = 3 and stock_item_id in (select stock_item_id from Stock_Item_Count where Stock_Holding_Group_ID in (1) and Stock_Count > 0))); GO update ssb set InitiationFeePaid = 1 where SSB_ID in ( select ssb_id from SSB_Payment where SSB_Payment_Type_ID=2 and Amount_Paid >0 and ssb_id in (select ssb_id from ssb_item where stock_item_id in (select Stock_Item_ID from stock_item where Item_Stock_Type_ID = 3 and stock_item_id in (select stock_item_id from Stock_Item_Count where Stock_Holding_Group_ID in (1) and Stock_Count > 0))) ); GO update Lay_Bye set LaybyStockStatusId = 3, TermId = 3 where Lay_Bye_Status_ID =1; GO update ssb set Initiated_By=2 ,Approved_By =2 where CreationDate > '2023-11-01' and Approved_By is null; GO update [System_User] set Sales_Code = SUBSTRING(sales_code,1,5) where len(sales_code) >5 and Global_User_ID is null; GO update SSB_Item set Redeemed =1,Redeemed_By = 'transfer from Pheonix to Cashpos' where ssb_id in (select ssb_id from ssb where CreationDate between '2023-01-01' and '2023-11-15') and Redeemed is null and NewContractID is null; update seller set Duplicate =1 where id_number in ( select ID_Number from ssb s join seller se on se.seller_id = s.Seller_ID where CreationDate > '2024-01-01' ) and seller_id not in (select se.Seller_ID from ssb s join seller se on se.seller_id = s.Seller_ID where CreationDate > '2024-01-01'); GO update SSB_Item set Redeemed = 1 where Redeemed_Date is not null and Redeemed is null; GO Use [master]; Go -- To allow advanced options to be changed. EXEC sp_configure 'show advanced options', 1; -- To update the currently configured value for advanced options. RECONFIGURE; -- To enable the feature. EXEC sp_configure 'xp_cmdshell', 1; -- To update the currently configured value for this feature. RECONFIGURE;